import SceneUi from "../scene/SceneUi";
import UiMgr from "../../common/uimgr/UiMgr";
import Model from "../../common/model/Model";
import Net from "../../common/net/Net";
import BaseUi from "../base/BaseUi";

const {ccclass, property} = cc._decorator;

@ccclass
export default class MainUi extends BaseUi {
    @property(cc.Node)
    bgNode:cc.Node=null;
    @property(cc.Label)
    nicknameLabel:cc.Label=null;

    
    start () {
        var scale = Math.max(cc.winSize.width/this.bgNode.width, cc.winSize.height/this.bgNode.height)
        this.bgNode.setScale(scale);
        this.modelEvent("model.account.nickname", ()=>{
            this.nicknameLabel.string = Model.model.account.nickname;
        });
    };
    enterRoomBtnClick () {
        Net.request("connector.entryHandler.enterRoom", {}, (err, data)=>{
            if (!err) {
                SceneUi.enterGame();
            }
        });
    };
    headClick () {
        UiMgr.showDialog("account", "AccountRenameDialog");
    };
    chatClick () {
        UiMgr.showDialog("chat", "ChatDialog");
    }
    exitGame () {
        Net.disConnect(()=>SceneUi.enterLogin());
    }
}
